const { Controller } = require('egg');
const { ctxBodyFormatter } = require('../util/formatter');

class TheClassController extends Controller {
  async index() {
    const { ctx, service } = this;
    const res = ctxBodyFormatter(await service.theClass.getAllTheClass());
    ctx.status = res.status;
    ctx.body = res.body;
  }

  async show() {
    const { ctx, service } = this;
    const theClass = { tcId: ctx.params?.id };
    const res = ctxBodyFormatter(await service.theClass.getTheClass(theClass));
    ctx.status = res.status;
    ctx.body = res.body;
  }

  async create() {
    const { ctx, service } = this;
    const theClass = ctx.request.body;
    const res = ctxBodyFormatter(await service.theClass.appendTheClass(theClass));
    ctx.status = res.status;
    ctx.body = res.body;
  }

  async update() {
    const { ctx, service } = this;
    const theClass = ctx.request.body;
    const res = ctxBodyFormatter(await service.theClass.updateTheClass(theClass));
    ctx.status = res.status;
    ctx.body = res.body;
  }

  async destroy() {
    const { ctx, service } = this;
    const theClass = { tcId: ctx.params?.id };
    const res = ctxBodyFormatter(await service.theClass.destroyTheClass(theClass));
    ctx.status = res.status;
    ctx.body = res.body;
  }
}

module.exports = TheClassController;
